package com.ruijiang.mapper.VmServiceMapper;

import com.ruijiang.dto.insert.NodeInsertDto;
import com.ruijiang.dto.page.RegionPageDto;
import com.ruijiang.entity.Node;
import com.ruijiang.vo.node.NodeEntryVO;
import com.ruijiang.vo.node.NodePageVO;
import com.ruijiang.vo.vm.VMInfoVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface NodeMapper {

    /**
     * 获取点位列表
     * @param dto
     * @return
     */
    List<NodePageVO> getNodeList(RegionPageDto dto);

    /**
     * 新增点位
     * @param node
     */
    void insertNode(Node node);

    /**
     * 修改点位
     * @param id
     * @param dto
     */
    void updateNodeById(String id, NodeInsertDto dto);

    /**
     * 删除点位
     * @param id
     */
    @Delete("delete from tb_node where id = #{id}")
    void deleteNodeById(String id);


    /**
     * 获取点位机器详情
     * @param id
     * @return
     */
    @Select("select inner_code,vm_status,last_supply_time from tb_vending_machine where node_id = #{id}")
    List<VMInfoVO> getVmListByNodeId(String id);

    /**
     * 获取点位信息
     * @param nodeId
     * @return
     */
    @Select("select * from tb_node where id = #{nodeId}")
    Node getNodeByNodeId(String nodeId);

    @Select("SELECT COUNT(vm.id) as vmCount \n" +
            "FROM tb_node tn\n" +
            "LEFT JOIN tb_vending_machine vm ON tn.id=vm.node_id \n" +
            "WHERE tn.id = #{id}  GROUP BY  tn.id ")
    String getNodeVMCountByNodeId(String id);

    @Select("SELECT owner_name as name,count(*) as value FROM tb_node n GROUP BY n.owner_name ")
    List<NodeEntryVO> getNodeCollect();

    @Select("select count(*) from tb_node")
    Integer getNodeCount();
}
